<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!--只在模块名下面有效 -->
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>效能统计</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
.visit_rec_detail_win {
	text-align: left !important;
	padding: 10px 25px 25px 25px;
}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<div tabid="tabA" title="效能统计" lselected="true">
					<div class="searchArea">
						<form id="searchBar">
							<div class="fieldset1 clearFix">
								<div class="fieldBox col_33" id="cstMgrOrgCdId">
									<div class="label">分公司</div>
									<div class="field">
					                	<input name="buOrgCd" id="buOrgCd" type="text" value="" placeholder="请选择"  ltype="combobox">
					                </div>
								</div>
								<div class="fieldBox col_33" id="cstMgrOrgCdId">
									<div class="label">姓名</div>
									<div class="field">
										<input name="cstManagerNm" id="cstManagerNm" type="text"
											class="ui-textbox" value="">
									</div>
								</div>
								<div class="fieldBox">
									<div class="label">日期</div>
									<div class="field">
										<input ligerui="width: 120" name="visitTmStar"
											id="visitTmStar" type="text" class="ui-datepicker" value=""
											validate="{required:true}"> - <input
											ligerui="width: 120" name="visitTmEnd" id="visitTmEnd"
											type="text" class="ui-datepicker" value=""
											validate="{required:true}">
									</div>
								</div>
							
								<div class="clearFix"></div>
								<div class="btnsBox">
									<span id="searchBtn" class="sq-button sq-button-round">筛选</span>
									<span onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
									<span onclick="exportVisitAnalysis();"
										class="sq-button sq-button-round">导出</span>
									<font color="blue"><i class="ico_flasher_blue"></i>如未选择日期,则只能导出前30天的数据</font>
								</div>
							</div>
						</form>
					</div>
					
					<div id="ligergridDB" class="sq-grid"></div>
					
				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		var gridDB = null;
		var pageInApp = {}; // to 下一级子窗口 接口
		var queryFlag = '${queryFlag}'; //只查询列表
		var pageInTab = null;
		var loadedTabs = [];
		var visitMessage = $('#visitMessage');
		var visitRecTotal;
		$(function() {
			initTab();
			initGridDB(); //初始化待办列表
			initOrgTree();
			$("#searchBar").ligerForm();
			$("#searchBtn").click(function(event) {
				reloadGrid();
			});
			$('#closeAttachmentsView').click(function() {
				closeAttachmentsView();
			});
		});
	
		//重新加载GRID
		function reloadGrid() {
			var form = new liger.get("searchBar");
			var data = form.getData();
			for (name in data) {
				console.log('name:' + name + ',data:' + data[name]);
				gridDB.setParm(name, data[name]);
			}
			;
			gridDB.reload();
		}
	
		//初始化列表
		function initGridDB() {
			$("#ligergridDB").ligerGrid({
				url : '<%=path%>/spl/splvisitrec/initAnalysisList.do',
				method : 'get',
				columns : [
					{
						display : '姓名',
						name : 'cstManagerNm',
						width : 80,
						enabledSort : false
					},
					{
						display : '分公司',
						name : 'orgCdNm',
						minWidth : 100,
						enabledSort : false
					},
					{
						display : '拜访次数',
						name : 'visitNum',
						minWidth : 100,
						enabledSort : false,
						render : function(rowdata, index, value){
							var r = '';
							r += '<a href="javascript:searchVisitRec(\'';
							r += rowdata.cstManagerNm;
							r += '\')">';
							r += value;
							r += '</a>';
							return r;
						}
					},
					{
						display : '拜访经销商数量',
						name : 'visitCstNum',
						minWidth : 150,
						enabledSort : false,
						render : function(rowdata, index, value){
							var r = '';
							r += '<a href="javascript:toVisitSplAnalysisPage(';
							r += rowdata.cstManagerId;
							r += ')">';
							r += value;
							r += '</a>';
							return r;
						}
					},
					{
						display : '经销商维护数量',
						name : 'cstNums',
						minWidth : 150,
						enabledSort : false,
						render : function(rowdata, index, value){
							var r = '';
							r += '<a href="javascript:toSplAnalysisPage(';
							r += rowdata.cstManagerId;
							r += ')">';
							r += value;
							r += '</a>';
							return r;
						}
					}/* ,
					{
						display : '经销商维护数量',
						name : 'cstNums',
						minWidth : 80,
						enabledSort : false
					} */
				],
				pageSize : 10,
				pageSizeOptions : [ 10, 20, 30, 40, 50, 100 ], //按照自己的喜好选择不同的页面显示条数
				root : 'rows',
				record : 'total',
				hideLoadButton : true,
				width : '100%',
				height : '100%',
				heightDiff : -30,
				//checkbox : true,
				rownumbers : true,
				onAfterShowData : function() {
					$(".gridTip").grid_ligerTip();
					SetIframe_height();
				},
				onLoaded : function (grid) {
					console.log(grid);
					grid.toggleLoading(null);
					console.log(grid.data.total);
					///if (null == visitRecTotal) {
						visitRecTotal = grid.data.total;
					//}
				}
			});
			gridDB = liger.get("ligergridDB");
			gridDB.setHeight(100);
			gridDB.options.isSingleCheck = true;
		}
	
		//初始化组织架构树
		 var searchOrgTree = null;
	  	function initOrgTree(){
	  		$("#buOrgCd").ligerComboBox({
	            selectBoxWidth: 240,
	            selectBoxHeight: 150,
	            treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
	            textField:"tName",
	            valueField:"tCode",
	            tree: {
	                url: '<%=path%>/customer/cstbscinfo/initOrgTree.do',
	                ajaxType: 'get',
	                checkbox: false,
	                parentIcon: "none",
	                childIcon: "none",
	                textFieldName:"tName",
	                idFieldName:"tCode",
	                onSuccess: function () {
	                }
	            }
	        });
	  	}
	
		<!-- 导出效能统计 -->
		function exportVisitAnalysis() {
			//alert();
			var wait_dialog;
			var form = new liger.get("searchBar");
			var data = form.getData();
			$.ajax({
				type : 'get',
				dataType : 'json',
				data : {
					'buOrgCd' : data['buOrgCd'],
					'visitTmStar' : data['visitTmStar'],
					'visitTmEnd' : data['visitTmEnd'],
					'cstManagerNm' : data['cstManagerNm'],
					'visitRecTotal' : visitRecTotal
				},
				url : '<%=path%>/spl/splvisitrec/exportVisitAnalysis.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : '正在导出拜访记录信息...',
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						console.log(msg.data);
						//window.open(msg.data);
						window.location.href = msg.data;
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				}
			});
		}
		
		// 打开单个客户经理所有拜访记录页面
		function searchVisitRec (_cstManagerNm){
			console.log(_cstManagerNm);
			parent.mainApp.f_addTab('tab_spl_visit_rec'+_cstManagerNm,'拜访记录','<%=path%>/spl/splvisitrec/toVisitListByOnePage.do?cstManagerNm='+_cstManagerNm);
		}
		
		// 打开统计拜访经销商次数页面
		function toVisitSplAnalysisPage(_cstManagerId){
			parent.mainApp.f_addTab('tab_visit_spl_analysis'+_cstManagerId,'拜访记录','<%=path%>/spl/splvisitrec/toVisitSplAnalysisPage.do?cstManagerId='+_cstManagerId);
		}
		
		// 打开统计拜访经销商页面
		function toSplAnalysisPage(_cstManagerId){
			parent.mainApp.f_addTab('tab_spl_analysis'+_cstManagerId,'拜访记录','<%=path%>/spl/splvisitrec/toSplAnalysisPage.do?cstManagerId='+_cstManagerId);
		}
	
		//格式化时间
		function renderDate2(rowdata, index, value) {
			var dateStr = "";
			if (null != value) {
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
			}
			return dateStr;
		}
	
		function clearBtn() {
			clearLigerForm("searchBar");
			liger.get("buOrgCd").clear();//清空树
		}
	
		function iframeResize() {
			if (parent.mainApp) {
				parent.mainApp.parentTab.onResize();
			}
			;
		}
	
		//初始化Tab页
		function initTab() {
			pageInTab = $("#pageInTab").ligerTab({
				height : 'auto',
				contextmenu : false,
				minIframeHeight : GET_minIframeHeight(),
				onAfterSelectTabItem : function(tabid) {
					currTab = tabid; //赋值是哪个Tab页面
					if (loadedTabs.indexOf(tabid) < 0) {
						loadedTabs.push(tabid);
						switch (tabid) {
						case "tabB":
							pageInTab.setTabItemSrc(tabid, "<%=path%>/bizflow/rskUsrAchLog/toMyAchievementsPage.do");
							break;
						}
					}
					;
					SetIframe_height();
				}
			});
	
			$.extend(true, pageInApp, {
				pageInTab : pageInTab
			});
		}
	</script>

</body>
</html>
